package com.kgc.community.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.kgc.community.mapper.StallMapper;
import com.kgc.community.pojo.Stall;
import com.kgc.community.pojo.StallExample;
import com.kgc.community.service.StallService;
import org.junit.Test;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class StallServiceImpl implements StallService {

    @Resource
    StallMapper stallMapper;


    @Override
    public PageInfo<Stall> selectAll(StallExample example, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        PageHelper.orderBy("id desc");
        /*StallExample example = new StallExample();
        StallExample.Criteria criteria = example.createCriteria();
        StallExample.Criteria criteria1 = example.createCriteria();
        if(stall.getParkingdeadline() != null){
            //example.createCriteria().andParkingdeadlineBetween(stall.getParkingdeadline(),stall.getParkingdeadline());

        }
        if(stall.getCarId() != null&&stall.getCarId() !=""){
            example.createCriteria().andCarIdLike("%"+stall.getCarId()+"%");
        }*/
        List<Stall> stalls = stallMapper.selectByExample(example);
        PageInfo<Stall> pageInfo = new PageInfo<>(stalls);
        return pageInfo;
    }
    //增加方法

    @Override
    public int addStall(Stall stall) {
        return stallMapper.insertSelective(stall);
    }

    //根据id查询
    @Override
    public Stall selectById(Integer id) {

        return stallMapper.selectByPrimaryKey(id);
    }

    //修改方法
    @Override
    public int updateById(Stall stall) {

        return stallMapper.updateByPrimaryKeySelective(stall);
    }
}
